import { toHandlerKey, camelize } from '../shared/index'

export function emit(instance, event: string, ...agrs) {
    // console.log("emit- event", event)
    // console.log("emit-instance", instance)
    // console.log("...agrs" ,...agrs);

    const { props } = instance;
    // console.log(props);
    
    // 解析 event 
    // 支持 小驼峰格式（ex:changeAge）和 '-'横线分割格式（ex:change-age)
    const handler = props[toHandlerKey(camelize(event))];
    // handler 存在就执行
    handler && handler(...agrs)

}